<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* 
* Module default for frontpage
* @author DANG DINH HUNG
*
*/
class Home extends Public_Controller
{
	
	public function __construct()
	{
		parent::__construct();
		$this->load->model( array('home_m','escort_invoice_lines_m') ); 
		breadcumb_reset();
		$this->home_m->crontab_services();
		
		//echo  $this->config->config['base_url'];
		remove_ssl();
       // print_r($_SERVER);
	}
	
	function test(){
		$this->email_sender->sendEmailToUser_escortRegister(7);
		//echo $this->escort_invoice_lines_m->getTaxOfCountry(8);
		//echo slugify('Cataluña');
		
	}
	
	function clear(){
		removeSystemCaching_ioc();
	}
	
	public function index()
	{
		breadcumb(2,array(language_translate('breadcumb_browser_escort'), '#'));	
		
		$this->template->append_metadata("<meta name=\"keywords\" content=\"".language_translate('meta_keyword_homepage')."\" />");
		$this->template->append_metadata("<meta name=\"description\" content=\"".language_translate('meta_description_homepage')."\" />");
		
		$this->template
			->title( language_translate('brower_title_homepage') )
			->build('index');
	}
	
	function browse(){
		$this->load->view('browse_escort');
	}
	
	function profile(){
		$segs = $this->uri->segment_array();
	 	$escort_id = $segs[count($segs)-1]; 
		$locationString = getLocationZoneOfEscort($escort_id);
		$ESCORT = $this->escort_entity->init('id',$escort_id);
		$desc = $ESCORT->getDescription(get_language_id(),$ESCORT->getId());
		
		$metadesc = str_replace( array('$1','$2','$3'), array($ESCORT->getEscortName(),$locationString,$desc), language_translate('meta_description_profilepage'));
		$this->template->append_metadata("<meta name=\"description\" content=\"".$metadesc."\" />");
		
		$this->template->title( str_replace( array('$1','$2'),array($ESCORT->getEscortName(),$locationString), language_translate('brower_title_profilepage') ) );
		$this->template
			->build('profile');
	}
	
	function search(){
		$location = $this->home_m->findLocationInfo();
		 
		breadcumb(2,array(language_translate('breadcumb_search'), site_url_lang("home/search")));	
		if( $location['country'] AND $location['country_id'] != 0 ){	
			breadcumb(3, array($location['country'],
						site_url_lang("home/search?country_id=".$location['country_id'].'&state_id=-1')));
		}	
		
		if( $location['state'] AND $location['state_id'] != 0 ){	
			breadcumb(4, array($location['state'],
						site_url_lang("home/search?country_id=".$location['country_id'].'&state_id='.$location['state_id'])));
		}					
		if( $location['province'] AND $location['province_id'] != 0 ){				
			breadcumb(5, array($location['province'],
							site_url_lang("home/search?country_id=".$location['country_id'].'&state_id='.$location['state_id'].'&province_id='.$location['province_id'])
					)
				);
		}		
		if(  $location['city'] AND $location['city_id'] != 0 ){
			breadcumb(6, array( $location['city'],
							site_url_lang("home/search?country_id=".$location['country_id'].'&state_id='.$location['state_id'].'&province_id='.$location['province_id'].'&city_id='.$location['city_id'])
					)
				); 	
		}
		
		$locationString = '';
		if($location['country']){
			$locationString = $location['country'];
		}
		if($location['state']){
			$locationString .= ', '.$location['state'];
		}
		if($location['province']){
			$locationString .= ', '.$location['province'];
		}
		if($location['city']){
			$locationString .= ', '.$location['city'];
		}
		
		$this->template->title( str_replace('$1',$locationString, language_translate('brower_title_searchpage') ) );
        
        if($this->input->get('tm') == 'ag'){
            $agency_id = intval($this->input->get('uid'));
            $U = $this->user_entity->init('id',$agency_id);
            $stringDesc = str_replace('$1',$U->getName(),language_translate('search_escort_of_agent_desc')); 
            if($U){
                $this->template->title( $stringDesc );
            }
        }
        
		$this->template->append_metadata("<meta name=\"keywords\" content=\"".language_translate('meta_keyword_searchpage')."\" />");
		$this->template->append_metadata("<meta name=\"description\" content=\"".language_translate('meta_description_searchpage')."\" />");
		
		if(!isset($_GET['is_async'])){
			$this->template
			->build('search');
		}else{
			$this->load->view('search_escort');
		}
	}
	
	function search_page(){
		$this->load->view('search_escort');
	}
	
	function top_escorts(){
		breadcumb(2,array(language_translate('breadcumb_top_escort'), site_url_lang("home/top_escorts")));	
		if(isset($_GET['async'])){
			$this->load->view('top_escorts_async');
		}else{
			$this->template->title( language_translate('brower_title_topescorts') );
			$this->template->build('top_escorts');
		}	
	}
	
	function change_language(){
		$id = intval($this->input->post('id',TRUE));
		$LANG = $this->language_entity->init('id',$id);
		set_language_code($LANG->getCode());
		echo "ok";
		exit();
	}
	
	function contactus(){
		$this->home_m->contactus();
		exit();
	}
	
	function contact_notify(){
		$this->load->view('contact_notify');
	}
	
	function contact(){
		breadcumb(2,array(language_translate('breadcumb_contact'), site_url_lang("home/contact")));
		$this->template->title( language_translate('brower_title_contactpage') );
		$this->template
			->build('contact');
	}
	
	///////////////////////////////////////////////////////////////////////
	function loadAsyncYearCalendar(){
		$this->load->model('escort_zone_m');
		$this->escort_zone_m->loadYearCalendar();
		exit();
	}
	
	function submit_visitor_send_message(){
		$this->load->model('escort_zone_m');
		$this->escort_zone_m->submit_visitor_send_message();
	}
	
	function updateNumberClicked(){
		$this->home_m->updateNumberClicked();
		exit();
	}
	
	function updateNumberSeeMobilePhone(){
		$this->home_m->updateNumberSeeMobilePhone();
		exit();
	}
	
	function bannerclicked(){
		$this->home_m->bannerclicked();
		exit();
	}
	
	function report_abuse(){
		$this->home_m->report_abuse();
		exit();
	}
	///////////////////////////////////////////////////////////////////////
	
	function changeCountry_async(){
		$country_id = $this->input->post('country_id',0);
		echo $this->home_m->changeCountry_async($country_id);
		exit();
	}
	
	function changeState_async(){
		$this->home_m->changeState_async();
		exit();
	}
	
	function changeProvince_async(){
		$this->home_m->changeProvince_async();
		exit();
	}
	
	function re_captcha(){
		echo newCaptcha();
		exit();
	}
	
	function services_reg_async(){
		$this->load->model('escort_zone_m');
		$task = $this->uri->segment(3,''); 
		switch($task){
			case 'loadCountry':
				$this->escort_zone_m->services_load_country();
				break;
			case 'loadState':
				echo $this->escort_zone_m->services_load_state($this->input->get('service_country_id'));
				break;
			case 'loadProvince':
				echo $this->escort_zone_m->services_load_province($this->input->get('service_country_id'),$this->input->get('service_state_id'));
				break;
			case 'loadCity':
				echo $this->escort_zone_m->services_load_city($this->input->get('service_country_id'),$this->input->get('service_state_id'),$this->input->get('service_province_id'));
				break;
			case 'fetch_listing_id':
				echo $this->escort_zone_m->fetch_listing_id(
					$this->input->get('country_id'),$this->input->get('state_id'),
					$this->input->get('province_id'),$this->input->get('city_id')
				);	
			case 'cancelOrder':
				$this->escort_zone_m->cancelOrder();
				break;
		}	
		exit;
	}
	
	///////////////////////////////////////////////////////////////////
	function crontab_services(){
		$this->home_m->crontab_services();
	}
	
	
	//endclass
}